<?php global $setting;?>
<script type="text/javascript">
console.log(setting_card);
$(document).ready(function() {
	reloadListener();
    bindAjaxForm($("#s_s_profile_editform"),s_s_profile_onSuccess,s_s_profile_onError,"s_s_profile_dia");
	if(setting_card!="settings_profile"){return;}
    var data = JSON.parse($(".s_temple_setting.profile_settings").html());
    if (data.new) {
        $("#s_p_new").removeClass("hidden");
        return;
    }
    setRadiobox(data.profile.gender, "c_");
    var gender = data.profile.gender;
    $("#s_birthday").attr("value", data.profile.birthday);
    var user_type = data.profile.user_type;
    if (user_type == 0) $("#u_student").click();
    if (user_type == 1) $("#u_parent").click();
    if (user_type == 2) $("#u_teacher").click();
    $("#s_name").attr("value", data.profile.name);
    $("#s_introduce").html(data.profile.introduce);
    $("#s_motto").html(data.profile.motto);  

});

function s_s_profile_onError(data){
	showMessage("s_s_profile_message",-101,data);
}
function s_s_profile_onSuccess(data){
    try {
        showMessage("s_s_profile_message",data["code"], data["message"]);
    } catch(ex) {
    	showMessage("s_s_profile_message",-31, data);
    }
}

$('.ui.form').form({
    fields: {
        name: {
            identifier: 'name',
            rules: [{
                type: 'empty',
                prompt: '请输入你的名字'
            }]
        },
        motto: {
            identifier: 'motto',
            rules: [{
                type: 'empty',
                prompt: '请输入你的座右铭'
            }]
        },
        gender: {
            identifier: 'gender',
            rules: [{
                type: 'empty',
                prompt: '请选择你的性别'
            }]
        },
        date: {
            identifier: 'date',
            rules: [{
                type: 'empty',
                prompt: '请输入你的生日'
            }]
        },
        introduce: {
            identifier: 'introduce',
            rules: [{
                type: 'empty',
                prompt: '请输入你的介绍'
            }]
        },
        user_type: {
            identifier: 'user-type',
            rules: [{
                type: 'empty',
                prompt: '请选择你的账户类型'
            }]
        }
    }
});
</script>
<h2>修改个人信息</h2>
<div class="s_temple_setting profile_settings"><?php print_json_setting("profile_settings");?></div>
<div class="ui warning message hidden" id="s_p_new">
	<div class="header">在浏览之前，你必须完善你的注册信息</div>
	请在这里填写您的个人存档
</div>
<div class="ui success message hidden" id="s_s_profile_message"></div>
<form class="ui form ajaxform" id="s_s_profile_editform" url="index.php?mod=home&childmod=setting&ajax=ture&op=updateprofile">
	<div class="field">
		<label>姓名：</label> <input type="text" name="name" placeholder="name" id="s_name">
	</div>
	<div class="inline fields">
		<div class="field">
			<label>性别：</label>
			<div class="ui radio checkbox" id="c_false">
				<input type="radio" name="gender" value="0" class="hidden"> <label>男</label>
			</div>
		</div>
		<div class="field">
			<div class="ui radio checkbox" id="c_true">
				<input type="radio" name="gender" value="1" class="hidden"> <label>女</label>
			</div>
		</div>
	</div>
	<div class="inline fields">
		<div class="field">
			<label>账户类型：</label>
			<div class="ui radio checkbox" id="u_student">
				<input type="radio" name="user_type" value="0" class="hidden"> <label>学生</label>
			</div>
		</div>
		<div class="field">
			<div class="ui radio checkbox" id="u_parent">
				<input type="radio" name="user_type" value="1" class="hidden"> <label>家长</label>
			</div>
		</div>
		<div class="field">
			<div class="ui radio checkbox" id="u_teacher">
				<input type="radio" name="user_type" value="2" class="hidden"> <label>教职工</label>
			</div>
		</div>
	</div>
	<div class="field">
		<label>生日：</label> <input type="date" name="birthday" placeholder="yourbirthday" id="s_birthday">
	</div>
	<div class="field">
		<label>自我介绍</label>
		<textarea name="introduce" form="s_s_profile_editform" rows="3" id="s_introduce"></textarea>
	</div>
	<div class="field">
		<label>座右铭</label>
		<textarea name="motto" form="s_s_profile_editform" rows="1" id="s_motto"></textarea>
	</div>
	<div class="ui error message"></div>
	<button class="ui button" type="submit">保存</button>
</form>